import { IToolTipItem } from "../../../../../com/mui/manager/IToolTipItem";
import { DailyInfo } from "../../../model/DailyInfo";
import { Language } from "../../../../../extend/language/Language";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { FlyFootBmp } from "../../mapUI/flyFoot/FlyFootBmp";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Cache } from "../../../cache/Cache";
import { ToolTipsManager } from "../../../../../com/mui/manager/ToolTipsManager";
//class DailyItem
    
    export  class DailyItem /* flash.display.Sprite */ implements IToolTipItem
    {
        constructor()
        {
            
            buttonMode = true;
            this.initUI();
            return;
        }

        public get info(): DailyInfo
        {
            return this._info;
        }

        public initUI(): void
        {
            this._bg = new Object /* flash.display.Sprite */();
            this._bg.graphics.beginFill(0, 0);
            this._bg.graphics.drawRect(0, 0, this.width, this.height);
            this._bg.graphics.endFill();
            this._bg.mouseEnabled = false;
            this._bg.cacheAsBitmap = true;
            addChild(this._bg);
            this._selectLine = new Object /* flash.display.Sprite */();
            this._selectLine.mouseEnabled = false;
            this._selectLine.graphics.lineStyle(2, 65407, 1);
            this._selectLine.graphics.drawRoundRect(1, 0, this.width, (this.height - 1), 6, 6);
            this._selectLine.graphics.endFill();
            this._downLine = new Object /* flash.display.Sprite */();
            this._downLine.mouseEnabled = false;
            this._downLine.graphics.beginFill(880761, 1);
            this._downLine.graphics.lineStyle(2, 16744192, 0);
            this._downLine.graphics.drawRoundRect(1, 0, this.width, (this.height - 1), 6, 6);
            this._downLine.graphics.endFill();
            this._downLine.cacheAsBitmap = true;
            this._itemName = new Object /* flash.text.TextField */();
            this._itemName.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._itemName.width = 100;
            this._itemName.x = 40;
            this._itemName.y = 4;
            this._itemName.textColor = 16776960;
            this._itemName.text = Language.getString(90104);
            this._itemName.mouseEnabled = false;
            this._itemName.filters = [FilterConst.nameGlowFilter];
            addChild(this._itemName);
            this._itemLevel = new Object /* flash.text.TextField */();
            this._itemLevel.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._itemLevel.width = 100;
            this._itemLevel.x = 140;
            this._itemLevel.y = this._itemName.y;
            this._itemLevel.textColor = 11464703;
            this._itemLevel.text = Language.getString(90105);
            this._itemLevel.mouseEnabled = false;
            addChild(this._itemLevel);
            this._itemTime = new Object /* flash.text.TextField */();
            this._itemTime.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._itemTime.width = 100;
            this._itemTime.x = 260;
            this._itemTime.y = this._itemName.y;
            this._itemTime.mouseEnabled = false;
            this._itemTime.textColor = 11464703;
            this._itemTime.text = "08: 00: 00 - 20: 00: 00";
            addChild(this._itemTime);
            this._itemOpt = new Object /* flash.text.TextField */();
            this._itemOpt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._itemOpt.width = 100;
            this._itemOpt.x = 382;
            this._itemOpt.y = this._itemName.y;
            this._itemOpt.textColor = 65054;
            this._itemOpt.filters = [FilterConst.nameGlowFilter];
            this._itemOpt.addEventListener(flash.events.TextEvent.LINK, this.onOptLinkclickHandler);
            addChild(this._itemOpt);
            this._line = GlobalClass.getBitmap(ImagesConst.SplitLine);
            this._line.y = (this.height - 1);
            this._line.x = 0;
            this._line.width = this.width + 10;
            addChild(this._line);
            this._flyFoot = new FlyFootBmp();
            this._flyFoot.y = this._itemName.y;
            this._flyFoot.addEventListener(flash.events.MouseEvent.CLICK, this.onFlyFootClickHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
            return;
        }

        protected onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.selected(true);
            return;
        }

        protected onMouseOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.selected(false);
            return;
        }

        /* internal  */onFlyFootClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.DailyActiveFlyTo, this._info));
            return;
        }

        protected onOptLinkclickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.DailyActiveGoTo, this._info));
            return;
        }

        public updateData(arg1: DailyInfo): void
        {
            var loc1=null;
            this.dispose();
            this._info = arg1;
            if (arg1 != null) 
            {
                this._color = "#AEEFFF";
                this._nameColor = "#00ff00";
                if (this._info.condition == 2 || this._info.openByTime == 1 || arg1.isCurWeekInfo == false) 
                {
                    var loc2;
                    this._color = loc2 = "#C688C9";
                    this._nameColor = loc2;
                }
                else if (this._info.condition == 3 || this._info.openByTime == 2) 
                {
                    this._color = loc2 = "#8e8e8e";
                    this._nameColor = loc2;
                }
                else if (this._info.openByTime == 3) 
                {
                    this._nameColor = "#99cc00";
                    this._color = "#99cc00";
                }
                this._itemName.htmlText = HTMLUtil.addColor(arg1.name, this._nameColor);
                if (!(arg1.levelWorld == 0) && arg1.levelWorld > Cache.instance.role.curWorldLevel) 
                {
                    this._itemLevel.htmlText = HTMLUtil.addColor(Language.getStringByParam(20970, arg1.levelWorld.toString()), this._color);
                }
                else 
                {
                    this._itemLevel.htmlText = HTMLUtil.addColor(Language.getStringByParam(90108, arg1.level.toString()), this._color);
                }
                loc1 = Cache.instance.daily.getDailyActiveTime(arg1.type);
                if (loc1) 
                {
                    this._itemTime.htmlText = HTMLUtil.addColor(loc1, this._color);
                }
                else 
                {
                    this._itemTime.htmlText = HTMLUtil.addColor(arg1.time, this._color);
                }
                if (this._info.openByTime == 1 || this._info.isCurWeekInfo == false) 
                {
                    this._itemOpt.htmlText = HTMLUtil.addColor(Language.getString(20973), this._color);
                }
                else if (this._info.openByTime != 2) 
                {
                    if (this._info.openByTime != 3) 
                    {
                        if (this._color == "#AEEFFF") 
                        {
                            this._itemOpt.htmlText = "<u><a href=\'event: 0\'>" + HTMLUtil.addColor(arg1.opt, "#00fe1e") + "</a></u>";
                        }
                        else 
                        {
                            this._itemOpt.htmlText = "<u><a href=\'event: 0\'>" + HTMLUtil.addColor(arg1.opt, this._color) + "</a></u>";
                        }
                    }
                    else 
                    {
                        this._itemOpt.htmlText = HTMLUtil.addColor(Language.getString(20975), this._color);
                    }
                }
                else 
                {
                    this._itemOpt.htmlText = HTMLUtil.addColor(Language.getString(20974), this._color);
                }
                this._flyFoot.x = this._itemOpt.x + this._itemOpt.textWidth + 5;
                if (this._info.flyFoot && this._info.openByTime == 0 && this._info.isCurWeekInfo) 
                {
                    addChild(this._flyFoot);
                }
                this.toolTipData = this._info.toolTipData;
            }
            return;
        }

        public updateActiveTime(arg1: string): void
        {
            if (!(arg1 == null) && !(this.info == null) && !(this._color == null)) 
            {
                this._itemTime.htmlText = HTMLUtil.addColor(arg1, this._color);
            }
            return;
        }

        public selected(arg1: Boolean): void
        {
            this._selected = arg1;
            if (arg1) 
            {
                addChildAt(this._selectLine, 0);
            }
            else if (this._selectLine.parent) 
            {
                removeChild(this._selectLine);
            }
            return;
        }

        public get isSelected(): Boolean
        {
            return this._selected;
        }

        public mouseDown(arg1: Boolean): void
        {
            if (arg1) 
            {
                addChildAt(this._downLine, 0);
            }
            else if (this._downLine.parent) 
            {
                removeChild(this._downLine);
            }
            return;
        }

        public dispose(): void
        {
            if (this._flyFoot && this.contains(this._flyFoot)) 
            {
                removeChild(this._flyFoot);
            }
            this.selected(false);
            this.mouseDown(false);
            this.toolTipData = null;
            return;
        }

        public /* override */ get height(): number
        {
            return 30;
        }

        public /* override */ get width(): number
        {
            return 425;
        }

        public get toolTipData()
        {
            return this._tooltipData;
        }

        public set toolTipData(arg1)
        {
            if (arg1 == null || arg1 == "") 
            {
                ToolTipsManager.unregister(this);
            }
            else 
            {
                ToolTipsManager.register(this);
            }
            this._tooltipData = arg1;
            return;
        }

        protected /* var */_line: Object /* flash.display.Bitmap */;

        protected /* var */_itemName: Object /* flash.text.TextField */;

        protected /* var */_itemLevel: Object /* flash.text.TextField */;

        protected /* var */_itemTime: Object /* flash.text.TextField */;

        protected /* var */_itemOpt: Object /* flash.text.TextField */;

        protected /* var */_flyFoot: FlyFootBmp;

        protected /* var */_info: DailyInfo;

        protected /* var */_bg: Object /* flash.display.Sprite */;

        protected /* var */_selectLine: Object /* flash.display.Sprite */;

        protected /* var */_downLine: Object /* flash.display.Sprite */;

        protected /* var */_color: string;

        protected /* var */_nameColor: string;

        /* internal */ /* var */_selected: Boolean;

        /* internal */ /* var */_tooltipData;
    }
